<?php
session_start();
require "lib/lib/GoogleChart.php";
require 'lib/lib/markers/GoogleChartShapeMarker.php';
require 'lib/lib/markers/GoogleChartTextMarker.php';
include_once("../../app/dao/database.php");
include "../../config/tanggal.php";

$tanggal = new Tanggal;

$class_db = new Database;

//$class_db->connect->connect();

$query = "SELECT corder.order_date as date, corder.order_id as order_id, SUM(order_detail.total) as total 
        FROM corder INNER JOIN order_detail 
        ON corder.order_id = order_detail.order_id WHERE store=$_SESSION[id_toko] GROUP BY date ORDER BY order_id DESC LIMIT 0,7";

$hasil = $class_db->select_table($query);
//print_r($hasil);

$values = array();
$date = array();

foreach($hasil as $data){
    $values[] = $data['total'];
    $tanggal->set_tgl($data['date']);
    $date[] = $tanggal->get_tgl_indo();
}

//membalik values
$temp = array();

for($i=0;$i<count($values);$i++){
    $temp[] = 0;
}

$j=0;
for($i=count($values);$i>0;$i--){
    $temp[$i-1] = $values[$j];
    $j++;
}

//membalik tanggal
$temp1 = array();

for($i=0;$i<count($date);$i++){
    $temp1[] = 0;
}

$j=0;
for($i=count($date);$i>0;$i--){
    $temp1[$i-1] = $date[$j];
    $j++;
}


/************/
$chart = new GoogleChart('lc', 500, 300);

// manually forcing the scale to [0,100]
//$chart->setScale(0,100);

// add one line
$data = new GoogleChartData($temp);
$chart->addData($data);

// customize y axis
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawTickMarks(false)->setLabels(array()); //masih belom berhasil
$chart->addAxis($y_axis);

// customize x axis
$x_axis = new GoogleChartAxis('x');
//$x_axis->setTickMarks(5);
$x_axis->setDrawTickMarks(false)->setLabels($temp1);
$chart->addAxis($x_axis);

// add a shape marker with a border
$shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$shape_marker->setSize(6);
$shape_marker->setBorder(2);
$shape_marker->setData($data);
$chart->addMarker($shape_marker);

// add a value marker
$value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
$value_marker->setData($data);
$chart->addMarker($value_marker);

header('Content-Type: image/png');
//echo $chart->toHtml();
echo $chart;
//**************/
/**************
$chart = new GoogleChart('lc', 800, 154);
$chart->setAutoscale(GoogleChart::AUTOSCALE_VALUES);
$chart->setGridLines(0,50, 3,2);
$chart->setMargin(5);

$line = new GoogleChartData($values);
$line->setColor('000000');
$line->setThickness(3);
$line->setFill('eeeeee');
$chart->addData($line);

$m = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$m->setData($line);
$m->setColor('000000');
$m->setSize(7);
$m->setBorder(2);
$chart->addMarker($m);

$values = array_fill(0,sizeof($values)-2, null);


$line2 = new GoogleChartData($values);
$line2->setColor('000000');
$line2->setThickness(3);
$line2->setDash(4,2);
$line2->setFill('eeeeee');
$chart->addData($line2);

$m = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$m->setData($line2);
$m->setColor('ffffff');
$m->setSize(4);
$m->setBorder(4,'000000');
$m->setPoints(-1);
$chart->addMarker($m);

$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawLine(false);
$y_axis->setDrawTickMarks(false);
$y_axis->setLabels(array(null,35,70));
$y_axis->setFontSize(9);
$y_axis->setTickMarks(5);
$y_axis->setTickColor('ffffff');
$chart->addAxis($y_axis);

$x_axis = new GoogleChartAxis('x');
$x_axis->setDrawLine(false);
$x_axis->setLabels($date);
$x_axis->setLabelPositions(0,25.8,51.8);
$x_axis->setTickMarks(3);
$x_axis->setFontSize(9);
$chart->addAxis($x_axis);

if ( isset($_GET['debug']) ) {
	var_dump($chart->getQuery());
	echo $chart->validate();
	echo $chart->toHtml();
}
else{
	//header('Content-Type: image/png');
	echo $chart->toHtml();
}
**********/
